package com.gangwangchina.android.contactlib.model;

import java.util.HashMap;
import java.util.Map;

import com.gangwangchina.android.contactlib.ContactsInterface;


import android.provider.ContactsContract.CommonDataKinds.Website;

public class WebSite extends DataElement{
	public static final String URL = Website.URL;
	public static final String CONTENT_ITEM_TYPE = Website.CONTENT_ITEM_TYPE;


	public String url;

	/**
	 * Creates a new WebSite that is not (yet) present in the database
	 * @param url
	 * @return
	 */
	public static WebSite newWebSite(String url){
		return new WebSite(url);
	}

	/**
	 * Creates an object representation of a WebSite that is present in the database
	 * @param pcId
	 * @param url
	 * @return
	 */
	public static WebSite recoverWebsites(long pcId, String url){
		return new WebSite(pcId, url);
	}

	/**
	 * Creates a new WebSite
	 * @param pcId the PersonContact the WebSite is linked to
	 * @param url
	 */
	private WebSite(long pcId, String url){
		this(pcId);
		this.url = url;
	}

	private WebSite(String url){
		this(ContactsInterface.NO_ID, url);
	}

	private WebSite(long pcId){
		super(pcId, CONTENT_ITEM_TYPE);
	}



	@Override
	public String toString(){
		return url;
	}

	@Override
	public Map<String, Object> getDataColumns() {
		Map<String, Object> datas = new HashMap<String, Object>();
		datas.put(URL, url);
		return datas;
	}

	@Override
	public boolean setProperty(String key, Object value){
		if(key.equals(URL)) url = (String) value;
		else return super.setProperty(key, value);
		return true;
	}

	@Override
	public Object getProperty(String key){
		if(key.equals(URL)) return url;
		return super.getProperty(key);
	}
}